package com.xjy.spring.thrift.core;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;

import com.xjy.spring.thrift.config.ThriftServerConfig;

// 仅用于测试
public class SimpleThriftServer extends AbstractThriftServer {

    @Override
    protected void startThriftServer(TProcessor tProcessor, ThriftServerConfig config) throws TTransportException {
        System.err.println("start server, type is Simple, config is " + config);
        TServerSocket serverTransport = new TServerSocket(config.getPort());
        TServer.Args tArgs = new TServer.Args(serverTransport);
        tArgs.processor(tProcessor);
        tArgs.protocolFactory(new TBinaryProtocol.Factory());
        // simple sever 用于测试
        TServer server = new TSimpleServer(tArgs);
        // 此处会阻塞
        server.serve();
    }

    @Override
    protected void registerThriftServer(ThriftServerConfig config) {
        // TODO Auto-generated method stub

    }

}
